﻿Imports System.Data.SqlClient

Public Class TT_ThueNhaBUS
    Public Shared Function GetAll() As DataTable
        Dim listTTThueNha As New DataTable()

        listTTThueNha = TT_ThueNhaDAO.GetAll()

        Return listTTThueNha
    End Function

    Public Shared Function GetByID(ByVal sqlParameters As SqlParameter()) As List(Of TT_ThueNhaDTO)
        Dim listTT_ThueNha As List(Of TT_ThueNhaDTO)

        listTT_ThueNha = TT_ThueNhaDAO.GetByID(sqlParameters)

        Return listTT_ThueNha
    End Function

    Public Shared Sub Insert(ByVal tt_thue As TT_ThueNhaDTO)
        Dim parameters(3) As SqlParameter
        Dim para As SqlParameter = New SqlParameter("MaKhachThue", SqlDbType.VarChar)
        para.Direction = ParameterDirection.Input
        para.Value = tt_thue.strMaKhachThue
        parameters(0) = para

        para = New SqlParameter("MaNha", SqlDbType.VarChar)
        para.Direction = ParameterDirection.Input
        para.Value = tt_thue.strMaNha
        parameters(1) = para

        para = New SqlParameter("NgayThue", SqlDbType.Date)
        para.Direction = ParameterDirection.Input
        para.Value = tt_thue.dNgayThue
        parameters(2) = para

        para = New SqlParameter("Gia", SqlDbType.Money)
        para.Direction = ParameterDirection.Input
        para.Value = tt_thue.iGia
        parameters(3) = para

        TT_ThueNhaDAO.Insert(parameters)
    End Sub

    Public Shared Sub Delete(ByVal paraID As SqlParameter)
        TT_ThueNhaDAO.Delete(paraID)
    End Sub

    Public Shared Sub Update(ByVal tt_thue As TT_ThueNhaDTO)
        Dim parameters(3) As SqlParameter
        Dim para As SqlParameter = New SqlParameter("MaKhachThue", SqlDbType.VarChar)
        para.Direction = ParameterDirection.Input
        para.Value = tt_thue.strMaKhachThue
        parameters(0) = para

        para = New SqlParameter("MaNha", SqlDbType.VarChar)
        para.Direction = ParameterDirection.Input
        para.Value = tt_thue.strMaNha
        parameters(1) = para

        para = New SqlParameter("NgayThue", SqlDbType.Date)
        para.Direction = ParameterDirection.Input
        para.Value = tt_thue.dNgayThue
        parameters(2) = para

        para = New SqlParameter("Gia", SqlDbType.Money)
        para.Direction = ParameterDirection.Input
        para.Value = tt_thue.iGia
        parameters(3) = para

        TT_ThueNhaDAO.Update(parameters)
    End Sub

    Public Shared Sub delete_TTThue(ByVal matt As Integer)
        Dim parameters(1) As SqlParameter

        Dim para As SqlParameter = New SqlParameter("MaTTThueNha", SqlDbType.VarChar)
        para.Direction = ParameterDirection.Input
        para.Value = matt
        parameters(0) = para

        TT_ThueNhaDAO.Delete(para)
    End Sub
    
    Public Shared Function KiemTraDayDu(ByVal gia As String)
        Dim kq As Boolean
        If Not gia = "" Then
            kq = True
        Else
            kq = False
        End If
        Return kq
    End Function

    Public Shared Function TimKiemTTTheoQuan(ByVal maquan As Integer) As DataTable
        Dim listTTThueNha As New DataTable()

        Dim para As SqlParameter = New SqlParameter("maquan", SqlDbType.Int)
        para.Direction = ParameterDirection.Input
        para.Value = maquan

        listTTThueNha = TT_ThueNhaDAO.TimKiemTTTheoQuan(para)

        Return listTTThueNha
    End Function

    Public Shared Function TimKiemTTTheoGia(ByVal gia As Integer) As DataTable
        Dim listTTThueNha As New DataTable()

        Dim para As SqlParameter = New SqlParameter("gia", SqlDbType.Money)
        para.Direction = ParameterDirection.Input
        para.Value = gia

        listTTThueNha = TT_ThueNhaDAO.TimKiemTTTheoGia(para)

        Return listTTThueNha
    End Function
    Public Shared Function TimKiemTTTheoGia_Quan(ByVal maquan As Integer, ByVal gia As Integer) As DataTable
        Dim listTTThueNha As New DataTable()

        Dim para1 As SqlParameter = New SqlParameter("maquan", SqlDbType.Int)
        para1.Direction = ParameterDirection.Input
        para1.Value = maquan

        Dim para As SqlParameter = New SqlParameter("gia", SqlDbType.Money)
        para.Direction = ParameterDirection.Input
        para.Value = gia

        listTTThueNha = TT_ThueNhaDAO.TimKiemTTTheoGia_Quan(para1, para)

        Return listTTThueNha
    End Function
End Class
